package br.com.abril.wallet;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import br.com.abril.booking.ExecutiveBooking;
import br.com.abril.prevision.ExecutivePrevision;

public class WalletTeam {

	private String primeExecutive;
	private String apportionment;
	private String percentage;
	private String executive;
	private Date bookingDate;
	
	
	public WalletTeam() {
	}
	
	public String getPrimeExecutive() {
		return primeExecutive;
	}
	public void setPrimeExecutive(String primeExecutive) {
		this.primeExecutive = primeExecutive;
	}
	public String getApportionment() {
		return apportionment;
	}
	public void setApportionment(String apportionment) {
		this.apportionment = apportionment;
	}
	public String getPercentage() {
		return percentage;
	}
	public void setPercentage(String percentage) {
		this.percentage = percentage;
	}
	public String getExecutive() {
		return executive;
	}
	public void setExecutive(String executive) {
		this.executive = executive;
	}

	public Date getBookingDate() {
		return bookingDate;
	}

	public void setBookingDate(Date bookingDate) {
		this.bookingDate = bookingDate;
	}

	public void setBookingDate(String bookingDate) {
		try {
			this.bookingDate = new SimpleDateFormat("yyyy-MM-dd").parse(bookingDate);
		} catch (ParseException e) {
		}
	}

	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((apportionment == null) ? 0 : apportionment.hashCode());
		result = prime * result
				+ ((executive == null) ? 0 : executive.hashCode());
		result = prime * result
				+ ((percentage == null) ? 0 : percentage.hashCode());
		result = prime * result
				+ ((primeExecutive == null) ? 0 : primeExecutive.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		WalletTeam other = (WalletTeam) obj;
		if (apportionment == null) {
			if (other.apportionment != null)
				return false;
		} else if (!apportionment.equals(other.apportionment))
			return false;
		if (executive == null) {
			if (other.executive != null)
				return false;
		} else if (!executive.equals(other.executive))
			return false;
		if (percentage == null) {
			if (other.percentage != null)
				return false;
		} else if (!percentage.equals(other.percentage))
			return false;
		if (primeExecutive == null) {
			if (other.primeExecutive != null)
				return false;
		} else if (!primeExecutive.equals(other.primeExecutive))
			return false;
		return true;
	}
	
	
	
	public WalletTeam buildFrom(ExecutiveBooking executive) {
		
		WalletTeam team = new WalletTeam();
		team.setApportionment (executive.getPercentualRateio__c());
		team.setPercentage (  executive.getPorcentagemAtendimento__c());
		team.setPrimeExecutive (  executive.getPrincipalExecutivo__c());
		team.setExecutive (  executive.getExecutivoMigrado__c());
		return team;				
	}

	public WalletTeam buildFrom(ExecutivePrevision executive) {
		WalletTeam team = new WalletTeam();
		team.setApportionment (executive.getPercentualRateio__c());
		team.setPercentage (  executive.getPercentualAtendimento__c());
		team.setPrimeExecutive (  executive.getPrincipalExecutivo__c());
		team.setExecutive (  executive.getExecutivoMigrado__c());
		return team;
		
	}
	
	
	public List<WalletTeam> buildBookingTeamFrom (List<ExecutiveBooking> executives) {
		List<WalletTeam> walletTeams = new ArrayList<WalletTeam>();
		for ( ExecutiveBooking executive :  executives ) {
			walletTeams.add(  buildFrom(executive) );
		}
		return walletTeams;
	}

	public List<WalletTeam> buildPrevisionTeamFrom (List<ExecutivePrevision> executives) {
		List<WalletTeam> walletTeams = new ArrayList<WalletTeam>();
		for ( ExecutivePrevision executive :  executives ) {
			walletTeams.add(  buildFrom(executive) );
		}
		return walletTeams;
	}
	
	
}
